<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';

$tabs=array(
	array('op'=>'main','title'=>'填写企业信息'),
	array('op'=>'content','title'=>'添加客服提交资料'),
	array('op'=>'set','title'=>'配置后台'),
);
$steps=array('填写企业信息','企业微信后台开启《会话内容存档》','配置后台');

if($_RQ['op']=='main'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		if($post['renzheng']){
		}		
		$this->plugin_setting('archiveset',$postdata);
		exi('','','content');
	}
	$wxwork=pdo_get('core_account_wxwork',array('uniacid'=>$_SESSION['uniacid'],'isdefault'=>1));
	if(!$wxwork){
		$wxwork=pdo_get('core_account_wxwork',array('uniacid'=>$_SESSION['uniacid']));	
	}
	$return['item']=$this->plugin_setting('archiveset');
	$return['item']['alltitle']=$wxwork['alltitle'];
	$return['item']['appid']=$wxwork['appid'];
	$htmls=array(
		'type'=>'edit',
		'desc'=>'填写企业信息',
		'submit_title'=>'保存并下一步',
		'edit'=>array(
			array('type'=>'copy','title'=>'企业名称','name'=>'alltitle'),
			array('type'=>'copy','title'=>'企业ID','name'=>'appid'),
			array('type'=>'string','title'=>'企业代码','name'=>'code'),
			array('type'=>'string','title'=>'企业负责人','name'=>'username'),
			array('type'=>'string','title'=>'企业负责人电话','name'=>'mobile'),
		),
	);
	$return['htmls'][]=array('type'=>'steps','steps'=>$steps,'step'=>'1');
	$return['htmls'][]=$htmls;
	exi($return);
}
if($_RQ['op']=='content'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		if(!$postdata['isopen']){
			exi('请先开启会话内容存档！','error');
		}		
		$this->plugin_setting('archiveset',$postdata);
		exi('','','set');
	}
	$return['item']=$this->plugin_setting('archiveset');
	$return['item']['genqrcode']='../addons/jy_scrm/resource/images/genqrcode.png';
	$htmls=array(
		'type'=>'edit',
		'desc'=>'企业微信后台开启《会话内容存档》',
		'submit_title'=>'保存并下一步',
		'edit'=>array(
			array('type'=>'help','title'=>'开启《会话内容存档》','help'=>'https://work.weixin.qq.com/wework_admin/frame#financial/corpEncryptData'),
			array('type'=>'img_show','title'=>'手机企业微信扫码联系客服','name'=>'genqrcode'),
			array('type'=>'switch','title'=>'我已开启?','name'=>'isopen'),
		),
	);
	$return['htmls'][]=array('type'=>'steps','steps'=>$steps,'step'=>'2');
	$return['htmls'][]=$htmls;
	exi($return);
}
if($_RQ['op']=='set'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		if($post['renzheng']){
		}		
		$this->plugin_setting('archiveset',$postdata);
		exi('设置成功');
	}
	$return['item']=$this->plugin_setting('archiveset');
	$htmls=array(
		'type'=>'edit',
		'desc'=>'配置后台',
		'submit_title'=>'保存并下一步',
		'edit'=>array(
				array('type'=>'string','name'=>'appid','title'=>'应用ID','help'=>'《会话内容存档》；以ww或wx开头应用id（对应于旧的以tj开头的套件id）'),
				array('type'=>'string','name'=>'appsecret','title'=>'应用secret','help'=>'《会话内容存档》密钥；'),

		),
	);
	$return['htmls'][]=array('type'=>'steps','steps'=>$steps,'step'=>'3');
	$return['htmls'][]=$htmls;
	exi($return);
}